import java.util.Calendar;

public class Tool {

    public void updateFourth(double Amount,String s){

        Calendar calendar = Calendar.getInstance();
        if(Amount > 0)
            FourthWindow.detailsBuilder.append(calendar.get(Calendar.DAY_OF_MONTH)).append("日\t").append("  收入  \t\t").append(Amount).append("\t\t\t\t").append(s).append("\n");
        if(Amount < 0)
            FourthWindow.detailsBuilder.append(calendar.get(Calendar.DAY_OF_MONTH)).append("日\t").append("  支出  \t\t").append(Amount).append("\t\t\t\t").append(s).append("\n");

        FourthWindow.detailsTextArea.setText(FourthWindow.detailsBuilder.toString());

    }

    public void updateMainWindowData1(double incomeAmount) {
        // 获取当前主窗口数据
        double remaining = Double.parseDouble(FirstWindow.remainingLabel.getText().substring(5));
        int daysLeft = Integer.parseInt(FirstWindow.daysLeftLabel.getText().substring(8));


        // 更新数据
        remaining += incomeAmount;


        // 更新主窗口显示
        FirstWindow.remainingLabel.setText("本月剩余：" + remaining);
        FirstWindow.daysLeftLabel.setText("距离本月末天数：" + daysLeft);
    }

    public void updateMainWindowData2(double expenseAmount) {
        // 获取当前主窗口数据
        double remaining = Double.parseDouble(FirstWindow.remainingLabel.getText().substring(5));
        double expense = Double.parseDouble(FirstWindow.expenseLabel.getText().substring(5));
        int daysLeft = Integer.parseInt(FirstWindow.daysLeftLabel.getText().substring(8));
        double todayExpense = Double.parseDouble(FirstWindow.todayExpenseLabel.getText().substring(7));

        // 更新数据
        remaining += expenseAmount;
        expense += expenseAmount;
        expense = -expense;
        todayExpense += expenseAmount;
        todayExpense = -todayExpense;


        // 更新主窗口显示
        FirstWindow.remainingLabel.setText("本月剩余：" + remaining);
        FirstWindow.expenseLabel.setText("本月消费：" + expense);
        FirstWindow.daysLeftLabel.setText("距离本月末天数：" + daysLeft);
        FirstWindow.todayExpenseLabel.setText("今日消费金额：" + todayExpense);
    }

}
